import Vue from 'vue'
import Vuex from 'vuex'
import {UserMsg,profile} from '@/api/http'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isFold:false,
    elaside:'200px',
    token:'',
    UserMsg:[],
    profile:[],
  },
  getters: {
  },
  mutations: {
    updateIsFold(state) {
      state.isFold =!state.isFold
      if(state.isFold===false){
        state.elaside='200px'
      }else{
        state.elaside = '50px' 
      }
    },
    updataToken(state,val){
      state.token=val
      localStorage.setItem('RZtoken','Bearer'+' '+state.token)
    },
    updataUserMsg(state,val){
      state.UserMsg = val
    },
    updataprofile(state,val){
      state.profile = val
    }
  },
  actions: {
 async  getUserMsg(store,id){
      const res = await UserMsg(id)
      console.log(res.data.data)
      store.commit('updataUserMsg',res.data.data)
      // this.UserMsg = res.data.data 
    },
   async getprofile(store){
      const res = await profile()
      console.log('profile',res.data.data)
      store.commit('updataprofile',res.data.data)
      localStorage.setItem('RZprofile',store.state.profile)
    }
  },
  modules: {
  }
})
